package com.itheima.webserver.controller;

import com.itheima.commons.model.vo.MessageVo;
import com.itheima.commons.model.vo.PageResult;
import com.itheima.commons.model.vo.UserProfileVo;
import com.itheima.webserver.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Auther: alongchan
 * @Date: 2021/12/18 18:32
 * @Description: 用户管理
 */
@RestController
@RequestMapping("/manage")
public class ManageController {
    @Autowired
    private ManageService manageService;

    //动态记录和审核首页
    /*
     * @MethodName:userDataPageTurning
     * @ParamType:[java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String, java.lang.String]
     * @Param:[page, pagesize, userId, nickname, city]
     * @Exception:
     * @Return:ResponseEntity
     * @Description:用户数据翻页
     */
    @GetMapping("users")
    public ResponseEntity userDataPageTurning(@RequestParam(value = "page", defaultValue = "1", required = false) Integer page,
                                              @RequestParam(value = "pagesize", defaultValue = "10", required = false) Integer pagesize,
                                              @RequestParam(value = "id", required = false) String userId,
                                              @RequestParam(value = "nickname", required = false) String nickname,
                                              @RequestParam(value = "city", required = false) String city) {
        PageResult pageResult = manageService.userDataPageTurning(page, pagesize, userId, nickname, city);
        return ResponseEntity.ok(pageResult);
    }


    /*
     * @MethodName:userFreezeOperation
     * @ParamType:[java.util.Map<java.lang.String,java.lang.String>]
     * @Param:[params]
     * @Exception:
     * @Return:ResponseEntity
     * @Description:用户冻结操作
     */
    @PostMapping("users/freeze")
    public ResponseEntity userFreezeOperation(@RequestBody Map<String,String> params) {
        String userId = params.get("userId");
        String freezingTime = params.get("freezingTime");
        String freezingRange = params.get("freezingRange");
        String reasonsForFreezing = params.get("reasonsForFreezing");
        String frozenRemarks = params.get("frozenRemarks");
        String message = manageService.userFreezeOperation(userId,freezingTime,freezingRange,reasonsForFreezing,frozenRemarks);
        return ResponseEntity.ok(message);
    }

    /*
     * @MethodName:userUnfreezing
     * @ParamType:[java.util.Map<java.lang.String,java.lang.String>]
     * @Param:[params]
     * @Exception:
     * @Return:ResponseEntity
     * @Description:用户解冻操作
     */
    @PostMapping("users/unfreeze")
    public ResponseEntity userUnfreezing(@RequestBody Map<String,String> params) {
        String userId = params.get("userId");
        String reasonsForThawing = params.get("reasonsForThawing");
        String message = manageService.userUnfreezing(userId,reasonsForThawing);
        return ResponseEntity.ok(message);
    }


    /*
     * @MethodName:queryUserProfile
     * @ParamType:[java.lang.String]
     * @Param:[userId]
     * @Exception:
     * @Return:ResponseEntity
     * @Description:用户基本资料
     */
    @GetMapping("users/{userID}")
    public ResponseEntity queryUserProfile(@PathVariable(value = "userID")String userId) {
        UserProfileVo userProfileVo = manageService.queryUserProfile(userId);
        return ResponseEntity.ok(userProfileVo);
    }


    //动态审核首页-消息翻页
    @GetMapping("/messages")
    public ResponseEntity getUserMovementsRecord(@RequestParam Map<String, String> params) {
        PageResult pageResult = new PageResult();
        String uid = params.get("uid");
        if (uid!=null ) {
            //动态记录
            pageResult = manageService.getUserMovementsRecord(params);
        } else {
            //审核首页
            pageResult = manageService.getAllMessages(params);
        }
        return ResponseEntity.ok(pageResult);
    }

    //动态审核-通过
    @PostMapping("/messages/pass")
    public ResponseEntity messagePass(@RequestBody List<String> ids) {
        Map<String, String> result = manageService.passMessage(ids);
        return ResponseEntity.ok(result);
    }

    //动态审核-拒绝
    @PostMapping("/messages/reject")
    public ResponseEntity messageReject(@RequestBody List<String> ids) {
        Map<String, String> result = manageService.rejectMessage(ids);
        return ResponseEntity.ok(result);
    }

    //动态审核-撤销
    @PostMapping("/messages/revocation")
    public ResponseEntity messageRevocation(@RequestBody List<String> ids) {
        Map<String, String> result = manageService.revocationMessage(ids);
        return ResponseEntity.ok(result);
    }

    //消息置顶
    @PostMapping("/messages/{id}/top")
    public ResponseEntity messageTop(@PathVariable("id") String publishId) {
        String message = manageService.messageTop(publishId);
        return ResponseEntity.ok(message);
    }

    //消息取消置顶
    @PostMapping("/messages/{id}/untop")
    public ResponseEntity messageUntop(@PathVariable("id") String publishId) {
        String message = manageService.messageUntop(publishId);
        return ResponseEntity.ok(message);
    }

    //视频记录
    @GetMapping("/videos")
    public ResponseEntity getUserVideoRecord(@RequestParam Map<String, String> params) {
        PageResult pageResult = manageService.getUserVideoRecord(params);
        return ResponseEntity.ok(pageResult);
    }

    //消息详情
    @GetMapping("/messages/{id}")
    public ResponseEntity getMessageDetail(@PathVariable("id") String publishId) {
        MessageVo messageVo = manageService.getUserMessageDetail(publishId);
        return ResponseEntity.ok(messageVo);
    }

    //评论管理
    @GetMapping("/messages/comments")
    public ResponseEntity commentsManage(@RequestParam Map<String, String> params) {
        PageResult pageResult = manageService.getAllComments(params);
        return ResponseEntity.ok(pageResult);
    }

    //日志管理
    @GetMapping("/logs")
    public ResponseEntity logsManage(@RequestParam Map<String, String> params) {
        PageResult pageResult = manageService.getLogs(params);
        return ResponseEntity.ok(pageResult);
    }

}
